package com.ruoyi.web.controller.glzz;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.web.domain.glzz.TGlzzMenu;
import com.ruoyi.web.domain.glzz.TGlzzMenuSubject;
import com.ruoyi.web.domain.glzz.dao.TGlzzMenuAddDao;
import com.ruoyi.web.domain.glzz.dao.TGlzzMenuSetDao;
import com.ruoyi.web.domain.glzz.dao.TGlzzMenuSubjectAddDao;
import com.ruoyi.web.domain.glzz.dao.TGlzzMenuUpdateDao;
import com.ruoyi.web.domain.glzz.excel.TGlzzMenuExcelDao;
import com.ruoyi.web.service.glzz.ITGlzzMenuService;
import com.ruoyi.web.service.glzz.ITGlzzMenuSubjectService;
import com.ruoyi.web.utils.RevertEntityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * glzz菜单Controller
 *
 * @author sci
 * @date 2024-05-13
 */
@SuppressWarnings({"DefaultAnnotationParam", "PointlessBooleanExpression"})
@Api(value = "glzz菜单", tags = {"glzz菜单API"})
@RestController
@RequestMapping("/system/glzzMenuSubject")
public class TGlzzMenuSubjectController extends BaseController {
    @Autowired
    private ITGlzzMenuService tGlzzMenuService;
    @Autowired
    private ITGlzzMenuSubjectService tGlzzMenuSubjectService;
    @Resource
    RestTemplate restTemplate;

    /**
     * 查询glzz菜单列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "第几页，从1开始", required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "查询出多少条数据", required = false, paramType = "query"),
            @ApiImplicitParam(name = "nodeId", value = "菜单id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "parentNodeId", value = "菜单父id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "metaTitle", value = "菜单名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "app", value = "是否显示", required = false, paramType = "query"),
            @ApiImplicitParam(name = "web", value = "是否显示", required = false, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "是否启用", required = false, paramType = "query"),
            @ApiImplicitParam(name = "moduleIcon", value = "模块图标", required = false, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "路由名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "component", value = "组件名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "metaIcon", value = "显示图标", required = false, paramType = "query"),
            @ApiImplicitParam(name = "metaIconActive", value = "激活图标", required = false, paramType = "query"),
            @ApiImplicitParam(name = "address", value = "路由地址", required = false, paramType = "query"),
            @ApiImplicitParam(name = "freeUse", value = "免费使用", required = false, paramType = "query"),
            @ApiImplicitParam(name = "keepAlive", value = "前端缓存", required = false, paramType = "query"),
            @ApiImplicitParam(name = "remarks", value = "备注介绍", required = false, paramType = "query")
    })
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('system:glzzMenu:list')")
    @GetMapping("/list")
    public AjaxResult list(
            @RequestParam(value = "id", required = false) Long id,
            @RequestParam(value = "nodeId", required = false) String nodeId,
            @RequestParam(value = "parentNodeId", required = false) String parentNodeId,
            @RequestParam(value = "metaTitle", required = false) String metaTitle,
            @RequestParam(value = "app", required = false) Integer app,
            @RequestParam(value = "web", required = false) Integer web,
            @RequestParam(value = "status", required = false) Integer status,
            @RequestParam(value = "moduleIcon", required = false) String moduleIcon,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "component", required = false) String component,
            @RequestParam(value = "metaIcon", required = false) String metaIcon,
            @RequestParam(value = "metaIconActive", required = false) String metaIconActive,
            @RequestParam(value = "address", required = false) String address,
            @RequestParam(value = "freeUse", required = false) Long freeUse,
            @RequestParam(value = "keepAlive", required = false) Long keepAlive,
            @RequestParam(value = "remarks", required = false) String remarks
    ) {
        LambdaQueryWrapper<TGlzzMenu> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(Objects.nonNull(id), TGlzzMenu::getId, id);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(nodeId), TGlzzMenu::getNodeId, nodeId);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(parentNodeId), TGlzzMenu::getParentNodeId, parentNodeId);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(metaTitle), TGlzzMenu::getMetaTitle, metaTitle);
        lambdaQueryWrapper.eq(Objects.nonNull(app), TGlzzMenu::getApp, app);
        lambdaQueryWrapper.eq(Objects.nonNull(web), TGlzzMenu::getWeb, web);
        lambdaQueryWrapper.eq(Objects.nonNull(status), TGlzzMenu::getStatus, status);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(moduleIcon), TGlzzMenu::getModuleIcon, moduleIcon);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(name), TGlzzMenu::getName, name);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(component), TGlzzMenu::getComponent, component);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(metaIcon), TGlzzMenu::getMetaIcon, metaIcon);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(metaIconActive), TGlzzMenu::getMetaIconActive, metaIconActive);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(address), TGlzzMenu::getAddress, address);
        lambdaQueryWrapper.eq(Objects.nonNull(freeUse), TGlzzMenu::getFreeUse, freeUse);
        lambdaQueryWrapper.eq(Objects.nonNull(keepAlive), TGlzzMenu::getKeepAlive, keepAlive);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(remarks), TGlzzMenu::getRemarks, remarks);
        List<TGlzzMenu> list = tGlzzMenuService.list(lambdaQueryWrapper);
        return success(list);
    }

    /**
     * 导出glzz菜单列表
     */
    @ApiOperation("导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nodeId", value = "菜单id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "parentNodeId", value = "菜单父id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "metaTitle", value = "菜单名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "app", value = "是否显示", required = false, paramType = "query"),
            @ApiImplicitParam(name = "web", value = "是否显示", required = false, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "是否启用", required = false, paramType = "query"),
            @ApiImplicitParam(name = "moduleIcon", value = "模块图标", required = false, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "路由名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "component", value = "组件名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "metaIcon", value = "显示图标", required = false, paramType = "query"),
            @ApiImplicitParam(name = "metaIconActive", value = "激活图标", required = false, paramType = "query"),
            @ApiImplicitParam(name = "address", value = "路由地址", required = false, paramType = "query"),
            @ApiImplicitParam(name = "freeUse", value = "免费使用", required = false, paramType = "query"),
            @ApiImplicitParam(name = "keepAlive", value = "前端缓存", required = false, paramType = "query"),
            @ApiImplicitParam(name = "remarks", value = "备注介绍", required = false, paramType = "query")
    })
    @PreAuthorize("@ss.hasPermi('system:glzzMenu:export')")
    @Log(title = "glzz菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "nodeId", required = false) String nodeId,
                       @RequestParam(value = "parentNodeId", required = false) String parentNodeId,
                       @RequestParam(value = "metaTitle", required = false) String metaTitle,
                       @RequestParam(value = "app", required = false) Integer app,
                       @RequestParam(value = "web", required = false) Integer web,
                       @RequestParam(value = "status", required = false) Integer status,
                       @RequestParam(value = "moduleIcon", required = false) String moduleIcon,
                       @RequestParam(value = "name", required = false) String name,
                       @RequestParam(value = "component", required = false) String component,
                       @RequestParam(value = "metaIcon", required = false) String metaIcon,
                       @RequestParam(value = "metaIconActive", required = false) String metaIconActive,
                       @RequestParam(value = "address", required = false) String address,
                       @RequestParam(value = "freeUse", required = false) Long freeUse,
                       @RequestParam(value = "keepAlive", required = false) Long keepAlive,
                       @RequestParam(value = "remarks", required = false) String remarks
    ) {
        LambdaQueryWrapper<TGlzzMenu> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.like(StringUtils.isNotBlank(nodeId), TGlzzMenu::getNodeId, nodeId);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(parentNodeId), TGlzzMenu::getParentNodeId, parentNodeId);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(metaTitle), TGlzzMenu::getMetaTitle, metaTitle);
        lambdaQueryWrapper.eq(Objects.nonNull(app), TGlzzMenu::getApp, app);
        lambdaQueryWrapper.eq(Objects.nonNull(web), TGlzzMenu::getWeb, web);
        lambdaQueryWrapper.eq(Objects.nonNull(status), TGlzzMenu::getStatus, status);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(moduleIcon), TGlzzMenu::getModuleIcon, moduleIcon);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(name), TGlzzMenu::getName, name);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(component), TGlzzMenu::getComponent, component);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(metaIcon), TGlzzMenu::getMetaIcon, metaIcon);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(metaIconActive), TGlzzMenu::getMetaIconActive, metaIconActive);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(address), TGlzzMenu::getAddress, address);
        lambdaQueryWrapper.eq(Objects.nonNull(freeUse), TGlzzMenu::getFreeUse, freeUse);
        lambdaQueryWrapper.eq(Objects.nonNull(keepAlive), TGlzzMenu::getKeepAlive, keepAlive);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(remarks), TGlzzMenu::getRemarks, remarks);
        List<TGlzzMenu> list = tGlzzMenuService.list(lambdaQueryWrapper);
        ExcelUtil<TGlzzMenuExcelDao> util = new ExcelUtil<TGlzzMenuExcelDao>(TGlzzMenuExcelDao.class);
        List<TGlzzMenuExcelDao> tGlzzMenuExcelDaos = RevertEntityUtil.convertList(list, TGlzzMenuExcelDao.class);
        util.exportExcel(response, tGlzzMenuExcelDaos, "glzz菜单数据");
    }

    /**
     * 获取glzz菜单详细信息
     */
    @ApiOperation("详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id", required = true, paramType = "query"),
    })
    @PreAuthorize("@ss.hasPermi('system:glzzMenu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        LambdaQueryWrapper<TGlzzMenu> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(TGlzzMenu::getId, id);
        TGlzzMenu tGlzzMenu = tGlzzMenuService.getOne(lambdaQueryWrapper);
        if (Objects.isNull(tGlzzMenu)) {
            return AjaxResult.error("未查询到数据");
        }
        return success(tGlzzMenu);
    }

    /**
     * 新增glzz菜单
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('system:glzzMenu:add')")
    @Log(title = "glzz菜单", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TGlzzMenuAddDao tGlzzMenuAddDao
    ) {
        TGlzzMenu tGlzzMenu = new TGlzzMenu();
        // region 插入数据-参数填充
        tGlzzMenu.setNodeId(tGlzzMenuAddDao.getNodeId());
        tGlzzMenu.setParentNodeId(tGlzzMenuAddDao.getParentNodeId());
        tGlzzMenu.setMetaTitle(tGlzzMenuAddDao.getMetaTitle());
        tGlzzMenu.setApp(tGlzzMenuAddDao.getApp());
        tGlzzMenu.setWeb(tGlzzMenuAddDao.getWeb());
        tGlzzMenu.setStatus(tGlzzMenuAddDao.getStatus());
        tGlzzMenu.setModuleIcon(tGlzzMenuAddDao.getModuleIcon());
        tGlzzMenu.setName(tGlzzMenuAddDao.getName());
        tGlzzMenu.setComponent(tGlzzMenuAddDao.getComponent());
        tGlzzMenu.setMetaIcon(tGlzzMenuAddDao.getMetaIcon());
        tGlzzMenu.setMetaIconActive(tGlzzMenuAddDao.getMetaIconActive());
        tGlzzMenu.setAddress(tGlzzMenuAddDao.getAddress());
        tGlzzMenu.setFreeUse(tGlzzMenuAddDao.getFreeUse());
        tGlzzMenu.setKeepAlive(tGlzzMenuAddDao.getKeepAlive());
        tGlzzMenu.setRemarks(tGlzzMenuAddDao.getRemarks());
        // endregion
        boolean success = tGlzzMenuService.save(tGlzzMenu);
        if (success == false) {
            return toAjax(false);
        }
        return toAjax(true);
    }


    /**
     * 给对应企业保存菜单
     */
    @ApiOperation("给对应企业保存菜单")
    @PostMapping("saveMenuForSubject")
    public AjaxResult saveMenuForSubject(@RequestBody TGlzzMenuSubjectAddDao tGlzzMenuSubjectAddDao
    ) {
        List<TGlzzMenuSubject> list = tGlzzMenuSubjectService.lambdaQuery().eq(TGlzzMenuSubject::getSubjectCode, tGlzzMenuSubjectAddDao.getSubjectCode()).list();
        if (list.size() > 0) {
            boolean b = tGlzzMenuSubjectService.removeBatchByIds(list);
        }

        List<String> menuIds = tGlzzMenuSubjectAddDao.getMenuIds();
        if (Objects.isNull(menuIds) || menuIds.size() == 0) {
            return error("请选中菜单");
        }
        String subjectCode = tGlzzMenuSubjectAddDao.getSubjectCode();
        if (Objects.isNull(subjectCode) || StringUtils.isBlank(subjectCode)) {
            return error("请输入企业编码");
        }
        List<TGlzzMenuSubject> saveList = new ArrayList<>();
        for (String menuId : menuIds) {
            TGlzzMenuSubject tGlzzMenuSubject = new TGlzzMenuSubject();
            tGlzzMenuSubject.setMenuId(menuId);
            tGlzzMenuSubject.setSubjectCode(subjectCode);
            saveList.add(tGlzzMenuSubject);
        }
        boolean b = tGlzzMenuSubjectService.saveBatch(saveList);
        return success();
    }

    /**
     * 给对应企业保存菜单
     */
    @ApiOperation("给对应企业保存菜单")
    @PostMapping("handleDataToPinyin")
    public AjaxResult handleDataToPinyin(@RequestBody TGlzzMenuSubjectAddDao tGlzzMenuSubjectAddDao
    ) {
        List<TGlzzMenu> tGlzzMenus = tGlzzMenuService.listByIds(tGlzzMenuSubjectAddDao.getMenuIds());
        tGlzzMenus.forEach(item -> {
            if (StringUtils.isNotBlank(item.getMetaIcon())) {
                item.setMetaIcon(renameIcon(item.getMetaIcon()));
            }
            if (StringUtils.isNotBlank(item.getMetaIconActive())) {
                item.setMetaIconActive(renameIcon(item.getMetaIconActive()));
            }

        });
        tGlzzMenuService.updateBatchById(tGlzzMenus);
        return success();
    }

    private static String renameIcon(String originalText) {
        StringBuilder pinyinBuilder = new StringBuilder();
        char[] chars = originalText.toCharArray();
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);

        for (char c : chars) {
            if (Character.toString(c).matches("[\\u4e00-\\u9fa5]+")) { // 检查是否为中文字符
                try {
                    String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
                    if (pinyinArray != null) {
                        pinyinBuilder.append(pinyinArray[0]);
                    }
                } catch (BadHanyuPinyinOutputFormatCombination e) {
                    e.printStackTrace();
                }
            } else {
                // 非中文字符直接添加到拼音字符串中（如果需要的话）
                // 这里可以根据你的需求来处理非中文字符
                pinyinBuilder.append(c);
            }
        }

        return pinyinBuilder.toString();
    }

    /**
     * 批量复制菜单
     */
    @ApiOperation("批量复制菜单")
    @PostMapping("copyMenus")
    public AjaxResult copyMenus(@RequestBody TGlzzMenuSubjectAddDao tGlzzMenuSubjectAddDao
    ) {


        List<String> menuIds = tGlzzMenuSubjectAddDao.getMenuIds();
        if (Objects.isNull(menuIds) || menuIds.size() == 0) {
            return error("请选中菜单");
        }
        List<TGlzzMenu> tGlzzMenus = tGlzzMenuService.listByIds(menuIds);
        List<TGlzzMenu> saveMenus = new ArrayList<>();
        for (TGlzzMenu tGlzzMenu : tGlzzMenus) {
            TGlzzMenu tGlzzMen = new TGlzzMenu();
            BeanUtils.copyProperties(tGlzzMenu, tGlzzMen);
            tGlzzMen.setId(IdUtils.simpleUUID());
            tGlzzMen.setNodeId(tGlzzMenu.getNodeId() + "_复制");
            if (!tGlzzMenu.getParentNodeId().equals(0) && !tGlzzMenu.getParentNodeId().equals("0")) {
                tGlzzMen.setParentNodeId(tGlzzMenu.getParentNodeId() + "复制");
            }
            saveMenus.add(tGlzzMen);
        }
        boolean b = tGlzzMenuService.saveBatch(saveMenus);
        return success();
    }


    /**
     * 修改glzz菜单
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('system:glzzMenu:edit')")
    @Log(title = "glzz菜单", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public AjaxResult update(@RequestBody TGlzzMenuUpdateDao tGlzzMenuUpdateDao
    ) {
        if (Objects.isNull(tGlzzMenuUpdateDao.getId())) {
            return AjaxResult.error("修改失败，未传入id");
        }
        LambdaQueryWrapper<TGlzzMenu> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(TGlzzMenu::getId, tGlzzMenuUpdateDao.getId());
        TGlzzMenu tGlzzMenu = tGlzzMenuService.getOne(lambdaQueryWrapper);
        if (Objects.isNull(tGlzzMenu)) {
            return AjaxResult.error("修改失败，未查询到数据");
        }
        // region 更新数据-参数填充
        if (tGlzzMenuUpdateDao.getNodeId() != null) {
            tGlzzMenu.setNodeId(tGlzzMenuUpdateDao.getNodeId());
        }
        if (tGlzzMenuUpdateDao.getParentNodeId() != null) {
            tGlzzMenu.setParentNodeId(tGlzzMenuUpdateDao.getParentNodeId());
        }
        if (tGlzzMenuUpdateDao.getMetaTitle() != null) {
            tGlzzMenu.setMetaTitle(tGlzzMenuUpdateDao.getMetaTitle());
        }
        if (tGlzzMenuUpdateDao.getApp() != null) {
            tGlzzMenu.setApp(tGlzzMenuUpdateDao.getApp());
        }
        if (tGlzzMenuUpdateDao.getWeb() != null) {
            tGlzzMenu.setWeb(tGlzzMenuUpdateDao.getWeb());
        }
        if (tGlzzMenuUpdateDao.getStatus() != null) {
            tGlzzMenu.setStatus(tGlzzMenuUpdateDao.getStatus());
        }
        if (tGlzzMenuUpdateDao.getModuleIcon() != null) {
            tGlzzMenu.setModuleIcon(tGlzzMenuUpdateDao.getModuleIcon());
        }
        if (tGlzzMenuUpdateDao.getName() != null) {
            tGlzzMenu.setName(tGlzzMenuUpdateDao.getName());
        }
        if (tGlzzMenuUpdateDao.getComponent() != null) {
            tGlzzMenu.setComponent(tGlzzMenuUpdateDao.getComponent());
        }
        if (tGlzzMenuUpdateDao.getMetaIcon() != null) {
            tGlzzMenu.setMetaIcon(tGlzzMenuUpdateDao.getMetaIcon());
        }
        if (tGlzzMenuUpdateDao.getMetaIconActive() != null) {
            tGlzzMenu.setMetaIconActive(tGlzzMenuUpdateDao.getMetaIconActive());
        }
        if (tGlzzMenuUpdateDao.getAddress() != null) {
            tGlzzMenu.setAddress(tGlzzMenuUpdateDao.getAddress());
        }
        if (tGlzzMenuUpdateDao.getFreeUse() != null) {
            tGlzzMenu.setFreeUse(tGlzzMenuUpdateDao.getFreeUse());
        }
        if (tGlzzMenuUpdateDao.getKeepAlive() != null) {
            tGlzzMenu.setKeepAlive(tGlzzMenuUpdateDao.getKeepAlive());
        }
        if (tGlzzMenuUpdateDao.getRemarks() != null) {
            tGlzzMenu.setRemarks(tGlzzMenuUpdateDao.getRemarks());
        }
        // endregion

        boolean success = tGlzzMenuService.updateById(tGlzzMenu);
        if (success == false) {
            return toAjax(false);
        }
        return toAjax(true);
    }


    /**
     * 修改glzz菜单
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('system:glzzMenu:edit')")
    @Log(title = "glzz菜单", businessType = BusinessType.UPDATE)
    @PostMapping("handleSetGlzzMenu")
    public AjaxResult handleSetGlzzMenu(@RequestBody TGlzzMenuSetDao tGlzzMenuSetDao
    ) {
        String code = tGlzzMenuSetDao.getCode();
        List<Integer> idList = tGlzzMenuSetDao.getIdList();

//      使用http远程调用
        // 将code和idList封装到一个Map中，以便转换为JSON请求体
        Map<String, Object> requestBody = new HashMap<>();
        requestBody.put("code", code);
        requestBody.put("idList", idList);

        // 创建HTTP头部，设置内容类型为JSON
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 创建HttpEntity，它包含请求头和请求体
        HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);

        // 构建请求的URL（这里只是一个示例，你需要替换成实际的URL）
        String apiUrl = "http://your-api-endpoint/your-resource"; // 替换成你的API端点URL

        // 发送POST请求并获取响应
        ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, requestEntity, String.class);

        // 根据响应状态码判断请求是否成功
        boolean success = response.getStatusCode().is2xxSuccessful();


        if (success == false) {
            return toAjax(false);
        }
        return toAjax(true);
    }

    /**
     * 删除glzz菜单
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('system:glzzMenu:remove')")
    @Log(title = "glzz菜单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
//      在完善t todo
        return null;
    }
}
